package com.wxx.爬楼梯;

/**
 * @author: Jetwang
 * @date: 2022/3/16 8:55
 * @description: Solution
 * 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
 * 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢？
 * @version: 1.0
 */
public class Solution {
    public int climbStairs(int n) {
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        int result = 0;
        int start = 1;
        int end = 2;
        for (int i = 3; i <= n; i++) {
            result = start + end;
            start = end;
            end = result;
        }
        return result;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.climbStairs(3));
        System.out.println(solution.climbStairs(4));
        System.out.println(solution.climbStairs(5));
    }
}
